﻿@model GNSystem.Models.Forum

@{
    ViewBag.Title = Model.ForumName;
    var db = (ViewBag.Context as GNSystem.Models.DataContext);
    var users = db.UserProfiles.ToList();
    var posts = db.Posts.ToList();
}

<h2>Forum Display - @Model.ForumName</h2>

@if(db.Threads.Count(t=>t.ForumID == Model.ID) > 0)
{
    <table>
        <tr>
            <th>Subject</th>
            <th>Author</th>
            <th>Comments</th>
        </tr>
        @foreach (var thread in db.Threads.Where(t=>t.ForumID == Model.ID))
	    {
            <tr>
                <td>@Html.ActionLink(thread.Subject, "Details", "Thread", new RouteValueDictionary { {"id",  thread.ID } }, null)</td>
                <td>@Html.ActionLink(users.Find(u=>u.UserId == thread.UserID).UserName, "Details", "Account", new RouteValueDictionary { {"id",  thread.UserID } }, null)</td>
                <td>@posts.Count(u=>u.ThreadID == thread.ID)</td>
            </tr>
    	}
    </table>
}else{
    <p>No threads in '@Model.ForumName'</p>
}